from ui.components.base.widget import TgBaseWidget
from ui.components.layouts.vbox_layout import TgVBoxLayout
from ui.components.containers.tab_widget import TgTabWidget
from .margin_trading_tab import MarginTradingTab
from .index_data_tab import IndexDataTab
from .global_index_tab import GlobalIndexTab
from .options_volatility_tab import OptionsVolatilityTab


class RiskDataWidget(TgBaseWidget):
    def __init__(self):
        super().__init__()
        self.tabs = TgTabWidget()
        self.margin_trading_tab = MarginTradingTab()
        self.index_data_tab = IndexDataTab()
        self.global_index_tab = GlobalIndexTab()
        self.options_volatility_tab = OptionsVolatilityTab()
        self.tabs.addTab(self.index_data_tab, "指数数据")
        self.tabs.addTab(self.global_index_tab, "全球指数")
        self.tabs.addTab(self.margin_trading_tab, "融资融券")
        self.tabs.addTab(self.options_volatility_tab, "期权波动率")
        TgVBoxLayout(self).addWidget(self.tabs)

    def cleanup(self):
        """清理所有tab的资源"""
        if hasattr(self, 'margin_trading_tab'):
            self.margin_trading_tab.cleanup()
        if hasattr(self, 'index_data_tab'):
            self.index_data_tab.cleanup()
        if hasattr(self, 'global_index_tab'):
            self.global_index_tab.cleanup()
        if hasattr(self, 'options_volatility_tab'):
            self.options_volatility_tab.cleanup()